document.ready(function() {
    webSpinner.spin(getItem('loadSpin'));

    setValue('menuid', getUrlParam('menuid'));
    getAutologOptionList();
    queryKey('ok', 'yes');
});

function getAutologOptionList() {
    var param = {};
    param.ctrl = 'record';
    param.func = 'getAutologOptionList';

    sendAjax(param, function(result) {
        loadOptionsItem('optionItemFloatDiv1', 'moduleInfo', result.moduleList, '模块');
        loadOptionsItem('optionItemFloatDiv2', 'operaterInfo', result.operaterList, '人员');
    });
}

function queryKey(flag, permission = 'no') {
    clearSelect();
    resetPageBar(flag);

    var param = {};
    param.team = 'console';
    param.ctrl = 'record';
    param.func = 'getAutologList';
    param.moduleInfo = getAjaxValue('moduleInfo');
    param.operaterInfo = getAjaxValue('operaterInfo');
    param.statusInfo = getAjaxValue('statusInfo');
    param.startdate = encodeURIComponent(getDateInfo());
    param.page = getAjaxValue('page');
    param.menuid = getAjaxValue('menuid');
    param.permission = permission;

    sendAjax(param, function(result) {
        autolog.list = result.autolog;

        if (result.permission != null && result.permission != '') {
            autolog.permission = result.permission;
        }

        initPageBar(result.allPages);
        setHtml('listCount', result.listCount);

        setDisplay('loadSpin', 'none');
        setDisplay('mainBg', '');
        webSpinner.spin();
    });
}

function viewAutolog(logid) {
    openSlipIframeDiv('console.php?m=record&c=autologinfo&logid=' + logid);
}

function stopAutolog(logid) {
    setValue('tempid', logid);
    openConfirm('确定强制中止吗？', function() {
        var param = {};
        param.ctrl = 'record';
        param.func = 'stopAutolog';
        param.logid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            queryKey('page');
        });
    });
}

function repairAutolog(logid) {
    setValue('tempid', logid);
    openConfirm('确定已修复吗？', function() {
        var param = {};
        param.ctrl = 'record';
        param.func = 'repairAutolog';
        param.logid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            queryKey('page');
        });
    });
}

function deleteAutolog(logid) {
    setValue('tempid', logid);
    openConfirm('确定删除吗？', function() {
        var param = {};
        param.ctrl = 'record';
        param.func = 'deleteAutolog';
        param.logid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            queryKey('page');
        });
    });
}

function getDateInfo() {
    var dateInfo = getValue('dateInfo');
    if (dateInfo == '') {
        return '';
    }
    else if (dateInfo == '0') {
        return get_now_date();
    }
    else if (dateInfo == '1') {
        return get_add_day(-2);
    }
    else if (dateInfo == '2') {
        return get_add_day(-7);
    }
}